package com.example.costumview.customview;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Shader;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

import com.example.costumview.R;

public class BitmapShaderView extends View {
    private Paint mPaint;
    private Bitmap mBmp;
    public BitmapShaderView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        mPaint=new Paint();
        mBmp= BitmapFactory.decodeResource(getResources(), R.drawable.dog);
        mPaint.setShader(new BitmapShader(mBmp, Shader.TileMode.REPEAT,Shader.TileMode.REPEAT));
//        mPaint.setShader(new BitmapShader(mBmp, Shader.TileMode.MIRROR,Shader.TileMode.MIRROR));
//        mPaint.setShader(new BitmapShader(mBmp, Shader.TileMode.CLAMP,Shader.TileMode.CLAMP));

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        float left=getWidth()/3;
        float top=getHeight()/3;
        float right=getWidth()*2/3;
        float bottom=getHeight()*2/3;

        canvas.drawRect(left,top,right,bottom,mPaint);
    }
}
